// 扁平化取出code
export function flatPermission(perms) {
  let codes = [];
  perms.forEach((item) => {
    codes.push({
      code: item.code,
      title: item.title,
      icon: item.icon,
      permissionId: item.permissionId,
      parentPermissionId: item.parentPermissionId,
    });
    if (item.children) {
      codes = codes.concat(flatPermission(item.children));
    }
  });
  return codes;
}
const permissions = [
  {
    permissionName: "首页",
    permissionType: 1,
    title: "首页",
  },
  {
    permissionName: "域名管理",
    permissionType: 1,
    title: "域名管理",
    code: "domain",
    children: [
      {
        permissionName: "查看",
        permissionType: 1,
        title: "查看域名管理",
        code: "domain.view",
      },
      {
        permissionName: "新增",
        permissionType: 2,
        title: "新增域名",
        code: "domain.add",
      },
      {
        permissionName: "编辑",
        permissionType: 2,
        title: "编辑域名",
        code: "domain.edit",
      },
      {
        permissionName: "删除",
        permissionType: 2,
        title: "删除域名",
        code: "domain.delete",
      },
    ],
  },
  {
    permissionName: "服务管理",
    permissionType: 1,
    title: "服务管理",
    code: "service",
  },
  {
    permissionName: "策略管理",
    permissionType: 1,
    title: "策略管理",
    code: "policy",
    children: [
      {
        permissionName: "Web应用防护",
        permissionType: 1,
        title: "Web应用防护",
        code: "policy.web",
        children: [
          {
            permissionName: "查看",
            permissionType: 1,
            title: "查看Web应用防护",
            code: "policy.web.view",
          },
          {
            permissionName: "编辑",
            permissionType: 2,
            title: "编辑Web应用防护",
            code: "policy.web.edit",
          },
          {
            permissionName: "删除",
            permissionType: 2,
            title: "删除Web应用防护",
            code: "policy.web.delete",
          },
        ],
      },
      {
        permissionName: "网络访问控制",
        permissionType: 1,
        title: "网络访问控制",
        code: "policy.traffic",
        children: [
          {
            permissionName: "查看",
            permissionType: 1,
            title: "查看网络访问控制",
            code: "policy.traffic.view",
          },
          {
            permissionName: "编辑",
            permissionType: 2,
            title: "编辑网络访问控制",
            code: "policy.traffic.edit",
          },
          {
            permissionName: "删除",
            permissionType: 2,
            title: "删除网络访问控制",
            code: "policy.traffic.delete",
          },
        ],
      },
    ],
  },

  {
    permissionName: "系统管理",
    permissionType: 1,
    title: "系统管理",
    code: "sys-manage",
    children: [
      {
        permissionName: "管理员账号",
        permissionType: 1,
        title: "管理员账号",
        code: "sys-manage.user.view",
        icon: "user",
        children: [
          {
            permissionName: "查看",
            permissionType: 1,
            title: "查看管理员账号",
            code: "sys-manage.user.view",
            permissionCode: "admin-account:read",
          },
          {
            permissionName: "新增",
            permissionType: 2,
            title: "新增管理员账号",
            code: "sys-manage.user.add",
            permissionCode: "admin-account:create",
          },
          {
            permissionName: "编辑",
            permissionType: 2,
            title: "编辑管理员账号",
            code: "sys-manage.user.edit",
            permissionCode: "admin-account:update",
          },
          {
            permissionName: "删除",
            permissionType: 2,
            title: "删除管理员账号",
            code: "sys-manage.user.delete",
            permissionCode: "admin-account:delete",
          },
          {
            permissionName: "修改密码",
            permissionType: 2,
            title: "管理员账号修改密码",
            code: "sys-manage.user.change-password",
            permissionCode: "admin-account:update",
          },
          {
            permissionName: "启用",
            permissionType: 2,
            title: "启用管理员账号",
            code: "sys-manage.user.enable",
            icon: "",
            permissionCode: "admin-account:enable",
          },
          {
            permissionName: "禁用",
            permissionType: 2,
            title: "禁用管理员账号",
            code: "sys-manage.user.disable",
            icon: "",
            permissionCode: "admin-account:disable",
          },
        ],
      },
      {
        permissionName: "管理员角色",
        permissionType: 1,
        title: "管理员角色",
        code: "sys-manage.role.view",
        icon: "usergroup-add",
        children: [
          {
            permissionName: "查看",
            permissionType: 1,
            title: "查看管理员角色",
            code: "sys-manage.role.view",
            permissionCode: "admin-role:read",
          },
          {
            permissionName: "新增",
            permissionType: 2,
            title: "新增角色",
            code: "sys-manage.role.add",
            permissionCode: "admin-role:create",
          },
          {
            permissionName: "编辑",
            permissionType: 2,
            title: "编辑角色",
            code: "sys-manage.role.edit",
            permissionCode: "admin-role:update",
          },
          {
            permissionName: "删除",
            permissionType: 2,
            title: "删除角色",
            code: "sys-manage.role.delete",
            permissionCode: "admin-role:delete",
          },
          {
            permissionName: "分配权限",
            permissionType: 2,
            title: "角色分配权限",
            code: "sys-manage.role.permissions",
            permissionCode: "admin-role:update",
          },
        ],
      },
      {
        permissionName: "组织管理",
        permissionType: 1,
        title: "组织管理",
        code: "sys-manage.organization.view",
        icon: "cluster",
        children: [
          {
            permissionName: "查看",
            permissionType: 1,
            title: "查看组织管理",
            code: "sys-manage.organization.view",
            permissionCode: "organization:read",
          },
          {
            permissionName: "新增",
            permissionType: 2,
            title: "新增组织",
            code: "sys-manage.organization.add",
            permissionCode: "organization:create",
          },
          {
            permissionName: "编辑",
            permissionType: 2,
            title: "编辑组织",
            code: "sys-manage.organization.edit",
            permissionCode: "organization:update",
          },
          {
            permissionName: "删除",
            permissionType: 2,
            title: "删除组织",
            code: "sys-manage.organization.delete",
            permissionCode: "organization:delete",
          },
        ],
      },
      {
        permissionName: "日志配置",
        permissionType: 1,
        title: "日志配置",
        code: "sys-manage.logStorage.view",
        icon: "file-text",
        children: [
          {
            permissionName: "查看",
            permissionType: 1,
            title: "查看日志配置",
            code: "sys-manage.logStorage.view",
            permissionCode: "logConf:read",
          },
          {
            permissionName: "编辑",
            permissionType: 2,
            title: "编辑日志配置",
            code: "sys-manage.logStorage.edit",
            permissionCode: "logConf:update",
          },
        ],
      },
      {
        permissionName: "系统时间同步",
        permissionType: 1,
        title: "系统时间同步",
        code: "sys-manage.timeLock.view",
        icon: "clock-circle",
        children: [
          {
            permissionName: "查看",
            permissionType: 1,
            title: "查看系统时间同步",
            code: "sys-manage.timeLock.view",
            permissionCode: "system-time:read",
          },
          {
            permissionName: "编辑",
            permissionType: 2,
            title: "编辑系统时间同步",
            code: "sys-manage.timeLock.edit",
            permissionCode: "system-time:update",
          },
        ],
      },
    ],
  },
];

let id = 0;
function transformPermission(permission, parentPermissionId = 0) {
  for (let i = 0; i < permission.length; i++) {
    const item = permission[i];
    item.parentPermissionId = parentPermissionId;
    item.permissionId = ++id;
    if (item.children && item.children.length > 0) {
      transformPermission(item.children, item.permissionId);
    }
  }
}
transformPermission(permissions);
export const mockPermission = permissions;
window.permissions = permissions;
